package com.yan.demo3;

import com.yan.demo2.Book;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Properties;

/**
 * @author taoge
 * @Date 2024/8/14 14:18
 * @Description
 */
public class ReflectDemo3 {
    public static void main(String[] args) {

    }

    static{
        try {
            Properties prop = new Properties();

            InputStream stream = ReflectDemo3.class.getClassLoader().getResourceAsStream("spring.properties");

            prop.load(stream);

            String className = (String) prop.get("className");

            Class c = Class.forName(className);

            Constructor cons = c.getConstructor(String.class , String.class , Double.class , Date.class);

            cons.setAccessible(true);
            Book book = (Book) cons.newInstance("水浒传", "yft", 29.9, new Date());

            String methodName = (String) prop.get("methodName");
            Method method = c.getDeclaredMethod(methodName);
            System.out.println(method.invoke(book));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
